<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>验证props的单向绑定特性</title>
    <script src="vue.js"></script>
  </head>
  <body>
    <div id="app">
      <parent></parent>
    </div>
    <template id="child1">
      <div>
        <span>子组件数据</span>
        <input v-model="childData" />
        <span>输入的值为：{{ childData }}</span>
      </div>
    </template>
    <template id="parent1">
      <div>
        <span>父组件数据</span>
        <input v-model="parentData" />
        <span>输入的值为：{{ parentData }}</span>
        <child :child-data="parentData"></child>
      </div>
    </template>
    <script>
      //构建子组件child
      var childNode = {
        template: "#child1",
        props: ["childData"],
      };
      //构建父组件parent,在其中嵌套child组件
      var parentNode = {
        template: "#parent1",
        components: {
          child: childNode,
        },
        data() {
          return {
            parentData: "try",
          };
        },
      };
      var vm = new Vue({
        el: "#app",
        components: {
          parent: parentNode,
        },
      });
    </script>
  </body>
</html>
